package newXgame.hall
{
	import flash.events.Event;
	
	import newXgame.hall.globals.Globals;
	import newXgame.hall.object.GameTalkObject;
	import newXgame.hall.object.ListObject;
	import newXgame.hall.object.background.GameObjectBackground;
	import newXgame.hall.object.background.HallBackground;
	
	import org.dstart.draw.csuper.CSprite;

	public class GameRoomMain extends CSprite
	{
		private var bgSprite:HallBackground;		//	大厅最底层的背景框		
		private var bgGame:GameObjectBackground;	//	游戏对象背景框
		private var userList:ListObject;			//	用户列表
		private var lookList:ListObject;			//	观看者列表
		private var talkList:GameTalkObject;		//	聊天
		
		private var g:Globals;			//	全局变量
		
		public function GameRoomMain()
		{
			g = Globals.getObject();
			
			bgSprite = new HallBackground();
			bgGame = new GameObjectBackground();
			userList = new ListObject();
			lookList = new ListObject();
			talkList = new GameTalkObject();
			
			_root.addChild(bgSprite);
			_root.addChild(bgGame);
			_root.addChild(userList);
			_root.addChild(lookList);
			_root.addChild(talkList);
			
			this.addEventListener(Event.ADDED_TO_STAGE, onShowInStage);	
		}
		
		private function onShowInStage(e:Event):void
		{
			onReSizeEvent(null);
			
			this.stage.addEventListener(Event.RESIZE, onReSizeEvent);
		}
		
		private function onReSizeEvent(e:Event):void
		{
			var xBase:Number = g.xSpace;
			var yBase:Number = g.ySpace;
			var wMax:Number = this.stage.stageWidth - xBase * 2;
			var hMax:Number = this.stage.stageHeight - yBase * 2;

			wMax = (wMax < g.minWidth + xBase * 2) ? g.minWidth + xBase * 2 : wMax;
			hMax = (hMax < g.minHeight + yBase * 2) ? g.minHeight + yBase * 2 : hMax;
			
			xBase += 4;
			yBase += 4;			
			
			bgSprite.ChangeSize(wMax, hMax);			
			bgGame.ChangeSize(wMax - g.xGameSpace * 2.5 - userList.width, 
									hMax - g.yGameSpace * 2 - g.listBaseY);
			
			bgSprite.SetPlace(xBase, yBase);
			bgGame.SetPlace(g.xGameSpace, g.yGameSpace + g.listBaseY);			
			userList.SetPlace(wMax - userList.width - g.xGameSpace, g.listBaseY + g.yGameSpace);
			lookList.SetPlace(userList.x, userList.y + userList.height + g.yGameSpace/2);
			
			talkList.SetPlace(lookList.x, lookList.y + lookList.height + g.yGameSpace/2);
			talkList.ChangeSize(lookList.width, hMax - talkList.y - g.yGameSpace - 40);
		}
	}
}